﻿#include "playerinfo.h"
#include "ui_playerinfo.h"

#include <QBitmap>
#include <QPainter>
#include <QTimer>
#include <QPalette>

PlayerInfo::PlayerInfo(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PlayerInfo)
{
    ui->setupUi(this);

    setWindowFlag(Qt::FramelessWindowHint);

}

PlayerInfo::~PlayerInfo()
{
    delete ui;
}

void PlayerInfo::showLater()
{
    QTimer* timer = new QTimer();
    timer->start(1518);
    timer->setSingleShot(true);
    connect(timer, &QTimer::timeout, this, &PlayerInfo::show);
}

void PlayerInfo::initControl()
{

}

void PlayerInfo::setHumanLabel(Card::Group color)
{
    ui->labelPlayer->setText("玩家");
    QColor tempcolor = color == Card::RED ? QColor(155,23,27) : Qt::blue;
    QPalette palette = ui->labelPlayer->palette();
    palette.setColor(QPalette::WindowText, tempcolor);
    ui->labelPlayer->setPalette(palette);
}

void PlayerInfo::setAiLabel(Card::Group color)
{
    ui->labelPlayer->setText("电脑");
    QColor tempcolor = color == Card::RED ? Qt::red : Qt::blue;
    QPalette palette = ui->labelPlayer->palette();
    palette.setColor(QPalette::WindowText, tempcolor);
    ui->labelPlayer->setPalette(palette);
}

void PlayerInfo::setSelfLabel(Card::Group color)
{
    Q_UNUSED(color);
}

void PlayerInfo::setRivalLabel(Card::Group color)
{
    Q_UNUSED(color);
}

void PlayerInfo::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    // 自定义paint事件
    QStyleOption opt;
    opt.init(this);
    QPainter p(this);

    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
